import bianliang from "./bianliang.js";
import Bullet from "./Bullet.js";

class Hero {
	constructor() {
	    this.x = 200;
		this.y = 500;
		this.img = bianliang.resObj[1];
		this.width = this.img.width / 2;
		this.height = this.img.height / 2;
		this.isTwo = false;
	}
	
	draw(ctx) {
		ctx.drawImage(this.img, this.x, this.y, this.width, this.height);
	}
	
	//玩家飞机发射子弹的方法
	fire() {
		if (this.isTwo == false) {
			//说明是单排子弹
			var b = new Bullet(this.x, this.y);
			b.x = b.x + this.width / 2 - b.width / 2;
			bianliang.bulletList.push(b);
		} else {
			//说明双排子弹
			var b_left = new Bullet(this.x, this.y);
			//修正左边子弹坐标
			b_left.x = b_left.x + this.width / 4 - b_left.width / 2;
			
			var b_right = new Bullet(this.x, this.y);
			//修正右边子弹坐标
			b_right.x = b_right.x + this.width / 4 * 3 - b_right.width / 2;
			bianliang.bulletList.push(b_left);
			bianliang.bulletList.push(b_right);
		}
	}
}

export default Hero;